﻿namespace DesignModeConsole.行为型.访问者模式;

/// <summary>
/// 资源文件  增加功能后，资源文件类不需要修改
/// </summary>
public abstract class ResourceFile3
{
    public readonly string _filePath;

    public ResourceFile3(string filePath)
    {
        _filePath = filePath;
    }

    public abstract void Accept(Visitor extractor);
}

public class PptFile3 : ResourceFile3
{
    public PptFile3(string filePath) : base(filePath)
    {
    }

    public override void Accept(Visitor extractor)
    {
        extractor.Visit(this);
    }
}

public class PdfFile3 : ResourceFile3
{
    public PdfFile3(string filePath) : base(filePath)
    {
    }

    public override void Accept(Visitor extractor)
    {
        extractor.Visit(this);
    }
}

public class WordFile3 : ResourceFile3
{
    public WordFile3(string filePath) : base(filePath)
    {
    }

    public override void Accept(Visitor extractor)
    {
        extractor.Visit(this);
    }
}

/// <summary>
/// 提取方法
/// </summary>
public class Extractor2 : Visitor
{
    public void Visit(PptFile3 pptFile3)
    {
        Console.WriteLine("提取ppt 地址：" + pptFile3._filePath);
    }

    public void Visit(PdfFile3 pdfFile3)
    {
        Console.WriteLine("提取pdf 地址：" + pdfFile3._filePath);
    }

    public void Visit(WordFile3 wordFile3)
    {
        Console.WriteLine("提取ppt 地址：" + wordFile3._filePath);
    }
}

/// <summary>
/// 压缩服务
/// </summary>
public class CompressorService2 : Visitor
{
    public void Visit(PptFile3 pptFile3)
    {
        Console.WriteLine("压缩ppt 地址：" + pptFile3._filePath);
    }

    public void Visit(PdfFile3 pdfFile3)
    {
        Console.WriteLine("压缩pdf 地址：" + pdfFile3._filePath);
    }

    public void Visit(WordFile3 wordFile3)
    {
        Console.WriteLine("压缩word 地址：" + wordFile3._filePath);
    }
}

public interface Visitor
{
    void Visit(PptFile3 pptFile3);

    void Visit(PdfFile3 pdfFile3);

    void Visit(WordFile3 wordFile3);
}